package com.bckj.freshnow.cart.service;

import com.bckj.freshnow.cart.domain.cmd.CartItemAddCmdExe;
import com.bckj.freshnow.cart.entity.CartItem;
import com.bckj.freshnow.cart.repo.CartItemRepository;
import com.bckj.freshnow.cart.convert.CartItemConvert;
import com.bckj.freshnow.cart.model.CartItemResponse;
import com.bckj.freshnow.cart.model.CartItemRequest;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;


/**
 * 购物车商品表(CartItem)service
 *
 * @author makejava
 * @since 2025-04-28 15:27:50
 */
@Service
@RequiredArgsConstructor
public class CartItemService {

    private final CartItemRepository cartItemRepository;
    private final CartItemConvert cartItemConvert;
	private final CartItemAddCmdExe cartItemAddCmdExe;


    /**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
    public CartItemResponse save(CartItemRequest request) {
		return cartItemAddCmdExe.execute(request);
    }
    
    /**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	public boolean update(CartItemRequest request) {
        CartItem data = cartItemConvert.request2Bean(request);
        return cartItemRepository.updateById(data);
	}

	/**
	 * 根据Id移除
	 *
	 * @param id id
	 * @return boolean
	 */
	public boolean remove(Long id) {
		return cartItemRepository.removeById(id);
	}
}

